package com.qf;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author wbzs,
 * @date 2022/10/24,
 * @time 20:51,
 */
@SpringBootApplication
public class MyAppStarter12 {
    public static void main(String[] args) {
        SpringApplication.run(MyAppStarter12.class, args);
    }



    /**
     * 帮我们区分是不是同一个用户
     * @return
     */
    @Bean
    public KeyResolver myKeyResolver() {
        //通过获取用户的ip地址来判断是不是一个用户,根据实际情况,比如可以通过某个头或者token或者参数等等来区分,只要在这里自己返回即可
        return exchange -> Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
        //return exchange->Mono.just(exchange.getRequest().getQueryParams().getFirst("canshu")); //按照某个参数限流
    }


}
